<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>优惠券定义</title>
<%@include file="../include/include.jsp"%>
<link rel="stylesheet" type="text/css" href="${csspath }/public.css" />
<script type="text/javascript" src="${jspath}/jquery/jquery-2.1.3.js"></script>
<link rel="stylesheet" type="text/css"
	href="${bootstrapPath}/css/bootstrap.css" />
<script type="text/javascript" src="${bootstrapPath}/js/bootstrap.js"></script>
<script type="text/javascript" src="${layerPath }/layer.js"></script>
</head>
<style>
.icon {
	color: #FFFFFF;
}

.hr {
	text-align: center;
	width: 100%;
	background-color: #96c2f1;
	height: 1px;
}

.th_10 {
	width: 20%;
}

.btnLength {
	width: 50px;
}
</style>
<script>
	$(function() {
		$("#insertRedemption_btn")
				.click(
						function() {
							window.location = '${webcontext}/crmdp/dealer/coupon/toInsertRedemption';
						});

		$("#insertCoupon_btn")
				.click(
						function() {
							window.location = '${webcontext}/crmdp/dealer/coupon/toInsertCoupon';
						});

		$("#queryInfo_btn")
				.click(
						function() {
							search_form.action = "${webcontext}/crmdp/dealer/coupon/getTicketList?pager.currentPage=1";
							document.getElementById("search_form").submit();
						});
	});

	window.onload = function() {
		var qticketType = '${qticketType}';
		if (qticketType != null && qticketType != "") {
			$("#qticketType").val(qticketType);
		}
	};
	function search() {
		document.getElementById("search_form").submit();
	}

	//编辑
	function editTicket(id) {
		$("#ticketDefId").val(id);
		$("#search_form").attr('action','${webcontext}/crmdp/dealer/coupon/toEditTicket');
		$("#search_form").submit();
	}
	//删除
	function removeTicket(id) {
		//询问框
		jConfirm(
				"确定要删除数据吗？",
				"确认",
				function(r) {
					if (r) {
						var ticketName = $("#qticketName").val();
						var ticketType = $("#qticketType").val();
						$
								.ajax({
									url : '${webcontext}/crmdp/dealer/coupon/removeTicketInfoById',
									type : 'post',
									data : {
										'id' : id
									},
									success : function(data) {
										if (data.code == true) {
											jAlert(
													data.msg,
													"提示",
													function() {
														window.location = '${webcontext}/crmdp/dealer/coupon/getTicketList?qticketName='+ticketName+"&qticketType="+ticketType+"&pager.currentPage="+$("#currentPage").val();
													});
										} else if (data.code == false) {
											jAlert(data.msg, "提示");
										}
									},
									error : function() {
										jAlert("服务器错误，请联系管理员", "提示");
									},
								});
					}
				});
	}
</script>
<body>
	<div id="content">
		<form:form id="search_form"
			action="${webcontext}/crmdp/dealer/coupon/getTicketList"
			class="form-horizontal" method="post" modelAttribute="dto">
			<input type="hidden" id="ticketDefId" name="ticketDefId">
			<div>
				<div class="row">
					<div class="form-group" style="width: 100%">
						<label class="col-sm-2 control-label" for="qticketName">名称</label>
						<div class="col-sm-3">
							<input class="form-control input-sm" id="qticketName"
								name="qticketName" type="text" value="${qticketName}" />
						</div>
						<label class="col-sm-2 control-label" for="qticketType">类型</label>
						<div class="col-sm-3">
							<select id="qticketType" name="qticketType"
								class="form-control input-sm">
								<option value="N/A">--------请选择--------</option>
								<option value="COUPON">优惠券</option>
								<option value="REDEMPTION">提货券</option>
							</select>
						</div>
					</div>
				</div>
				<div class="text-center" style="margin-left: -200px;">
					<button id="queryInfo_btn" type="button"
						class="btn btn-success btn-sm">
						<i class="glyphicon glyphicon-search icon"></i>查询
					</button>
					<button id="insertRedemption_btn" type="button"
						class="btn btn-success btn-sm" style="width: 90px;">
						<i class=" glyphicon glyphicon-plus icon"></i>新建提货券
					</button>
					<button id="insertCoupon_btn" type="button"
						class="btn btn-success btn-sm" style="width: 90px;">
						<i class=" glyphicon glyphicon-plus icon"></i>新建优惠券
					</button>
				</div>
				<table id="data_tabs" class="table"
					style="width: 100%; margin-top: 20px;">
					<thead>
						<tr>
							<th class="th_10 hidden">ID</th>
							<th class="th_10">名称</th>
							<th class="th_10">类型</th>
							<th class="th_10">操作</th>
						</tr>
					</thead>
					<tbody>
						<core:forEach items="${ticketList}" var="list">
							<tr>
								<td class="hidden">${list.id}</td>
								<td>${list.ticketName}</td>
								<td><core:choose>
										<core:when test="${list.ticketType=='COUPON'}">
											<%=CodeTextUtils.getText("Ticket.TicketType", "COUPON")%>
										</core:when>
										<core:when test="${list.ticketType=='REDEMPTION'}">
											<%=CodeTextUtils.getText("Ticket.TicketType", "REDEMPTION")%>
										</core:when>
									</core:choose></td>
								<td>
									<button type="button"
										class="btn btn-success btn-xs btnLength"
										onClick="editTicket('${list.id}')">编辑</button>
									<button type="button" class="btn btn-success btn-xs btnLength"
										onClick="removeTicket('${list.id}')">删除</button>
								</td>
							</tr>
						</core:forEach>
					</tbody>
				</table>
				<div class="page_div">
					<%@include file="../common/page.jsp"%>
				</div>
			</div>
		</form:form>
	</div>

</body>
</html>